function frequentPatterns = aprioriMiner(transactions, minSupport)
    % 获取全集合（所有出现过的元素）
    itemSet = unique([transactions{:}]);
    maxK = max(cellfun(@length, transactions));
    frequentPatterns = {};
    
    % 将事务转为逻辑矩阵便于并行计算
    transactionMatrix = false(length(transactions), length(itemSet));
    for i = 1:length(transactions)
        transactionMatrix(i, ismember(itemSet, transactions{i})) = true;
    end

    % 从最大项数往下挖掘
    for k = maxK:-1:2
        candidateSets = nchoosek(itemSet, k);
        found = {};
        for i = 1:size(candidateSets, 1)
            candidate = candidateSets(i, :);
            idx = ismember(itemSet, candidate);
            support = sum(all(transactionMatrix(:, idx), 2));
            if support >= minSupport
                found{end+1} = candidate; %#ok<AGROW>
            end
        end
        if ~isempty(found)
            frequentPatterns = found;
            return;  % 找到最长的直接返回
        end
    end
end



